home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2008 September
/
PCWorld_2008-09_cd.bin
/
v cisle
/
sadanastroju
/
bookmark_previews-0.6.5-fx.xpi
/
chrome
/
content
/
thumbnailview.xml
< prev
next >
Wrap
Text File
|
2008-05-27
|
55KB
|
1,489 lines
<!-- ***** BEGIN LICENSE BLOCK *****
- Version: MPL 1.1/GPL 2.0/LGPL 2.1
-
- The contents of this file are subject to the Mozilla Public License Version
- 1.1 (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
- http://www.mozilla.org/MPL/
-
- Software distributed under the License is distributed on an "AS IS" basis,
- WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- for the specific language governing rights and limitations under the
- License.
-
- The Original Code is the Bookmarks Previews extension.
-
- The Initial Developer of the Original Code is
- John Marshall <JohnM555@gmail.com>.
- Portions created by the Initial Developer are Copyright (C) 2007
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
- John Marshall <JohnM555@gmail.com>
- Alternatively, the contents of this file may be used under the terms of
- either the GNU General Public License Version 2 or later (the "GPL"), or
- the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- in which case the provisions of the GPL or the LGPL are applicable instead
- of those above. If you wish to allow use of your version of this file only
- under the terms of either the GPL or the LGPL, and not to allow others to
- use your version of this file under the terms of the MPL, indicate your
- decision by deleting the provisions above and replace them with the notice
- and other provisions required by the LGPL or the GPL. If you do not delete
- the provisions above, a recipient may use your version of this file under
- the terms of any one of the MPL, the GPL or the LGPL.
-
- ***** END LICENSE BLOCK ***** -->
<bindings xmlns="http://www.mozilla.org/xbl"
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<binding id="thumbnailview">
<content>
<xul:scrollbox anonid="thumbnailScrollbox"
orient="vertical" id="thumbnailView" flex="1"
style="overflow: auto; -moz-user-focus: normal;"
context="_child">
<xul:hbox>
<xul:grid anonid="thumbnailGrid">
</xul:grid>
</xul:hbox>
<xul:menupopup id="bookmarksThumbPopup" anonid="bookmarksThumbPopup"
onpopupshowing="ThumbView.createViewContextMenu(event);"/>
</xul:scrollbox>
</content>
<implementation>
<method name="superConstructor">
<parameter name="event"/>
<body><![CDATA[
/* Load size from prefs */
var prefs = Components.classes["@mozilla.org/preferences-service;1"].
getService(Components.interfaces.nsIPrefService);
prefs = prefs.getBranch("extensions.thumbnails.");
var size = 1;
if (prefs.prefHasUserValue("size"))
size = prefs.getIntPref("size");
var thumbPopup = document.getElementById("thumbsSizePopup");
thumbPopup.childNodes[size].setAttribute("checked","true");
this.PREVIEW_WIDTH = this.PREVIEW_SIZES[size];
]]></body>
</method>
<property name="container">
<getter><![CDATA[
return document.getAnonymousElementByAttribute(this, "anonid", "thumbnailScrollbox");
]]></getter>
</property>
<!-- ThumbView -->
<field name="initiated">false</field>
<field name="PREVIEW_WIDTH">160</field>
<field name="PREVIEW_SIZES">[80,160,320]</field>
<field name="NOPREVIEW">"chrome://bookmarkpreviews/skin/nopreview.png"</field>
<field name="selectedItem">null</field>
<field name="bookmarks">null</field>
<field name="maxColCount">null</field>
<field name="colCount">null</field>
<field name="rowCount">null</field>
<field name="rows">null</field>
<property name="grid">
<getter><![CDATA[
return document.getAnonymousElementByAttribute(this,"anonid","thumbnailGrid");
]]></getter>
</property>
<method name="load">
<parameter name="images"/>
<body><![CDATA[
if (!images) return;
this.bookmarks = images;
var thumbDeck = this.parentNode;
var maxWidth = thumbDeck.boxObject.width;
var maxHeight = thumbDeck.boxObject.height;
var colCount = Math.floor(maxWidth / (this.PREVIEW_WIDTH+6));
if (colCount < 1) colCount = 1;
this.maxColCount = colCount;
var rowCount;
if (colCount > images.length) {
colCount = images.length;
rowCount = 1;
}
else{
rowCount = Math.ceil(images.length / colCount);
}
this.colCount = colCount;
this.rowCount = rowCount;
var grid = this.grid;
while (grid.lastChild)
grid.removeChild(grid.lastChild);
var xulNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
var cols = document.createElement("columns");
for (var i = 0; i< colCount; i++){
var col = document.createElement("column");
cols.appendChild(col);
}
grid.appendChild(cols);
var rows = document.createElement("rows");
for (var rowIndex = 0; rowIndex < rowCount; rowIndex++){
var row = document.createElement("row");
for (var colIndex = 0; colIndex < colCount; colIndex++){
var index = rowIndex * colCount + colIndex;
if (index >= images.length)
break;
row.appendChild(this._createThumb(images[index]));
}
rows.appendChild(row);
}
this.rows = rows;
grid.appendChild(rows);
if (colIndex>0){
var ele = rows.firstChild.firstChild;
this.selectElement(ele);
} else
this.selectElement(null);
]]></body>
</method>
<method name="_createThumb">
<parameter name="item"/>
<body><![CDATA[
var xulNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
var box = document.createElement("vbox");
box.setAttribute("pack","center");
box.setAttribute("align","center");
box.setAttribute("class","thumbnail");
var imageEle = document.createElement("image");
//imageEle.setAttribute("src",item.image);
var img = new Image();
img.src = item.image;
imageEle.setAttribute("width",this.PREVIEW_WIDTH);
if (item.image!=this.NOPREVIEW){
var self = this;
function thumb_img_load(){
imageEle.setAttribute("height",
parseInt(img.height * self.PREVIEW_WIDTH / img.width));
imageEle.setAttribute("maxHeight",imageEle.getAttribute("height"));
/* re-insert so the row/box will refresh the layout
otherwise the height gets stretched/not updated */
//var nextSibling = imageEle.parentNode.nextSibling;
//imageEle.parentNode.parentNode.insertBefore(imageEle.parentNode,nextSibling);
imageEle.setAttribute("src",item.image);
}
if (img.complete){
thumb_img_load();
}else{
imageEle.setAttribute("src",this.NOPREVIEW);
imageEle.setAttribute("height",
200 * this.PREVIEW_WIDTH / 320);
img.onload = thumb_img_load;
}
}
else{
imageEle.setAttribute("height",
200 * this.PREVIEW_WIDTH / 320);
imageEle.setAttribute("src",item.image);
}
var desc = document.createElement("label");
desc.setAttribute("value",item.caption);
desc.setAttribute("crop","end");
desc.setAttribute("class","thumbnail-label");
desc.setAttribute("width",this.PREVIEW_WIDTH);
desc.setAttribute("maxWidth",this.PREVIEW_WIDTH);
desc.setAttribute("style","max-width: "+this.PREVIEW_WIDTH+"px;");
var container = document.createElement("vbox");
container.setAttribute("class","thumbnail-container");
container.appendChild(imageEle);
container.appendChild(desc);
var spacer1 = document.createElement("spacer");
var spacer2 = document.createElement("spacer");
spacer1.setAttribute("flex","1");
spacer2.setAttribute("flex","1");
box.appendChild(spacer1);
box.appendChild(container);
box.appendChild(spacer2);
box.setAttribute("tooltiptext",item.caption);
//box.setAttribute("context","bookmarksThumbPopup");
imageEle.setAttribute("tooltiptext",item.caption);
box.setAttribute("ondraggesture","nsDragAndDrop.startDrag(event,ThumbView);");
return box;
]]></body>
</method>
<method name="updateThumbnail">
<parameter name="aURL"/>
<body><![CDATA[
if (!this.bookmarks) return;
for (var i = 0; i < this.bookmarks.length; i++){
if (this.bookmarks[i].url == aURL){
//dump("found thumbnail match: "+i+"\n");
var image = this.utils.getImageForURL(aURL);
this.bookmarks[i].image = image;
var thumb = this._createThumb(this.bookmarks[i]);
var toreplace = this.getElementAtIndex(i);
var isSelected = toreplace.getAttribute("selected");
toreplace.parentNode.replaceChild(thumb,toreplace);
if (isSelected == "true"){
this.selectedItem = null;
this.selectElement(thumb,null);
}
}
}
]]></body>
</method>
<method name="updateNodeTitle">
<parameter name="aNode"/>
<parameter name="aPrevValue"/>
<parameter name="aNewValue"/>
<body><![CDATA[
if (!this.bookmarks) return false;
var index = ThumbView.getIndexOfNode(aNode);
//dump("update index: "+index+"\n");
if (index==-1) return false;
this.bookmarks[index].caption = aNewValue;
var thumb = this._createThumb(this.bookmarks[index]);
var toreplace = this.getElementAtIndex(index);
var isSelected = toreplace.getAttribute("selected");
toreplace.parentNode.replaceChild(thumb,toreplace);
if (isSelected == "true"){
this.selectedItem = null;
this.selectElement(thumb,null);
}
return true;
]]></body>
</method>
<method name="handleKeypress">
<parameter name="event"/>
<body><![CDATA[
//dump("keypress:"+this.selectedItem+"|"+event+"\n");
var KeyEvent = Components.interfaces.nsIDOMKeyEvent;
if (!this.selectedItem)
return;
try{
switch(event.keyCode){
case KeyEvent.DOM_VK_LEFT:
if (event.altKey){
this.utils.back();
event.stopPropagation();
return;
}
var previous = this.selectedItem.previousSibling;
if (!previous){
previous = this.selectedItem.parentNode.lastChild;
}
this.selectElement(previous,event);
event.preventDefault();
event.stopPropagation();
break;
case KeyEvent.DOM_VK_RIGHT:
if (event.altKey){
this.utils.forward();
event.preventDefault();
event.stopPropagation();
return;
}
var next = this.selectedItem.nextSibling;
if (!next){
next = this.selectedItem.parentNode.firstChild;
}
this.selectElement(next,event);
event.preventDefault();
event.stopPropagation();
break;
case KeyEvent.DOM_VK_UP:
var colIdx = this._findElementIndex(this.selectedItem);
var rowIdx = this._findElementIndex(this.selectedItem.parentNode);
var newRow = null;
while (!newRow){
rowIdx--;
if (rowIdx<0) rowIdx = this.rowCount-1;
if ((newRow = this.rows.childNodes[rowIdx]).length>colIdx)
newRow = null;
}
if (newRow){
var next = newRow.childNodes[colIdx];
this.selectElement(next,event);
}
event.preventDefault();
event.stopPropagation();
break;
case KeyEvent.DOM_VK_DOWN:
var colIdx = this._findElementIndex(this.selectedItem);
var rowIdx = this._findElementIndex(this.selectedItem.parentNode);
var newRow = null;
while (!newRow){
rowIdx++;
if (rowIdx==this.rowCount) rowIdx = 0;
if ((newRow = this.rows.childNodes[rowIdx]).length>colIdx)
newRow = null;
}
if (newRow){
var next = newRow.childNodes[colIdx];
this.selectElement(next,event);
}
event.preventDefault();
event.stopPropagation();
break;
case KeyEvent.DOM_VK_RETURN:
case KeyEvent.DOM_VK_ENTER:
var tEvt = this.copyEvent(event);
tEvt.target = tEvt.originalTarget = this.selectedItem;
tEvt.button = 1;
this.performAction(tEvt);
event.preventDefault();
event.stopPropagation();
break;
case KeyEvent.DOM_VK_DELETE:
var rowIndex = this._findElementIndex(this.selectedItem.parentNode);
var colIndex = this._findElementIndex(this.selectedItem);
var index = rowIndex * this.colCount + colIndex;
ThumbViewUtils.removeItem(this.bookmarks[index]);
event.preventDefault();
event.stopPropagation();
break;
}
}catch(e){Components.utils.reportError(e);}
]]></body>
</method>
<!-- called from the thumbnail size menu -->
<method name="changeSize">
<parameter name="size"/>
<body><![CDATA[
if (this.PREVIEW_WIDTH != this.PREVIEW_SIZES[size]){
var prefs = Components.classes["@mozilla.org/preferences-service;1"].
getService(Components.interfaces.nsIPrefService);
prefs = prefs.getBranch("extensions.thumbnails.");
prefs.setIntPref("size",size);
this.PREVIEW_WIDTH = this.PREVIEW_SIZES[size];
this.load(this.bookmarks);
}
]]></body>
</method>
<method name="onResize">
<parameter name="event"/>
<body><![CDATA[
if (this.bookmarks!=null){
//dump("resize thumb view\n");
var colCount = Math.floor(this.parentNode.boxObject.width / (this.PREVIEW_WIDTH+6));
if (colCount != this.maxColCount && colCount > 0)
this.load(this.bookmarks);
}
]]></body>
</method>
<method name="_getClickTarget">
<parameter name="event"/>
<body><![CDATA[
return this._getTargetElement(event.originalTarget);
]]></body>
</method>
<method name="_getTargetElement">
<parameter name="target"/>
<body><![CDATA[
if (target){
if (target.className == "thumbnail")
return target;
else if (target.tagName == "image")
return target.parentNode.parentNode;
else if (target.className == "thumbnail-label")
return target.parentNode.parentNode;
else if (target.className == "thumbnail-container")
return target.parentNode;
}
return null;
]]></body>
</method>
<method name="copyEvent">
<parameter name="event"/>
<body><![CDATA[
var tEvt = {};
for (var p in event){
try{
tEvt[p] = event[p];
}catch(e){}
}
return tEvt;
]]></body>
</method>
<method name="isContainer">
<parameter name="index"/>
<body><![CDATA[
var node = this.nodeForIndex(index);
return this.nodeIsContainer(node);
]]></body>
</method>
<!-- changed from method to a property -->
<property name="selectedNode">
<getter><![CDATA[
return this.getElementNode(this.selectedItem);
]]></getter>
</property>
<method name="getElementNode">
<parameter name="target"/>
<body><![CDATA[
if (target && target.parentNode){
var rowIndex = this._findElementIndex(target.parentNode);
var colIndex = this._findElementIndex(target);
var index = rowIndex * this.colCount + colIndex;
return this.nodeForIndex(index);
}
return null;
]]></body>
</method>
<method name="nodeForIndex">
<parameter name="index"/>
<body><![CDATA[
if (index>-1 && index<this.bookmarks.length)
return this.bookmarks[index].node;
return null;
]]></body>
</method>
<method name="getIndexOfNode">
<parameter name="aNode"/>
<body><![CDATA[
var idx = -1;
for (var i = 0; i<this.bookmarks.length;i++){
if (this.bookmarks[i].node.itemId == aNode.itemId){
idx = i;
break;
}
}
return idx;
]]></body>
</method>
<method name="selectNode">
<parameter name="aNode"/>
<body><![CDATA[
var idx = this.getIndexOfNode(aNode);
if (idx == -1) return;
var ele = this.getElementAtIndex(idx);
this.selectElement(ele);
]]></body>
</method>
<method name="selectElement">
<parameter name="aTarget"/>
<parameter name="aEvent"/>
<body><![CDATA[
var target = this._getTargetElement(aTarget);
var xulNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
if (this.selectedItem!=null){
this.selectedItem.removeAttribute("selected");
}
this.selectedItem = target;
if (target){
this.selectedItem.setAttribute("selected","true");
var nsIScroll = this.container.boxObject.QueryInterface(
Components.interfaces.nsIScrollBoxObject);
nsIScroll.ensureElementIsVisible(this.selectedItem);
var index = this.getElementIndex(target);
this.onSelectionChanged(aEvent,index);
ThumbViewUtils.selectItem(this.bookmarks[index],aEvent);
}
else{
this.onSelectionChanged(aEvent,-1);
ThumbViewUtils.selectItem(null,aEvent);
}
]]></body>
</method>
<method name="_findElementIndex">
<parameter name="ele"/>
<body><![CDATA[
if (ele && ele.parentNode){
var nodes = ele.parentNode.childNodes;
for (var i = 0;i<nodes.length;i++){
if (nodes[i]==ele){
return i;
}
}
}
return -1;
]]></body>
</method>
<method name="getElementIndex">
<parameter name="ele"/>
<body><![CDATA[
/* ele is one of the thumbnails, ele.parentNode is a row */
if (ele && ele.parentNode){
var rowIndex = this._findElementIndex(ele.parentNode);
var colIndex = this._findElementIndex(ele);
var index = rowIndex * this.colCount + colIndex;
return index;
}
return -1;
]]></body>
</method>
<method name="getElementAtIndex">
<parameter name="index"/>
<body><![CDATA[
var rowIndex = Math.ceil((index+1) / this.colCount) - 1;
if (rowIndex<0) rowIndex = 0;
var colIndex = index - rowIndex * this.colCount;
var grid = this.grid;
var rows = grid.firstChild.nextSibling;
var ele = rows.childNodes[rowIndex].childNodes[colIndex];
return ele;
]]></body>
</method>
<method name="performAction">
<parameter name="event"/>
<body><![CDATA[
if (event.button==2) return;
var target = this._getClickTarget(event);
if (target){
var rowIndex = this._findElementIndex(target.parentNode);
var colIndex = this._findElementIndex(target);
var index = rowIndex * this.colCount + colIndex;
ThumbViewUtils.performAction(this.bookmarks[index],event);
}
]]></body>
</method>
<method name="setSize">
<parameter name="ele"/>
<parameter name="width"/>
<parameter name="height"/>
<body><![CDATA[
var xulNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
ele.setAttribute("height",height);
ele.setAttribute("width",width);
ele.setAttribute("flex", 0);
ele.style.height = height + "px";
ele.style.minHeight = ele.style.height;
ele.style.maxHeight = ele.style.height;
ele.style.width = width + "px";
ele.style.minWidth = ele.style.width;
ele.style.maxWidth = ele.style.width;
]]></body>
</method>
<!-- nsIPlacesView -->
<method name="getSelectionNodes">
<body><![CDATA[
var node = this.selectedNode;
if (node)
return [node];
return [];
]]></body>
</method>
<!-- nsDragAndDrop -->
<method name="onDragStart">
<parameter name="event"/>
<parameter name="xferData"/>
<parameter name="dragAction"/>
<body><![CDATA[
try{
//dump("dragstart\n");
// Drag and Drop does not work while a tree view is sorted.
//dump("is sorted?: "+this.isSorted+"\n");
if (this.isSorted)
throw Components.results.NS_OK;
var nodes = this.getSelectionNodes();
for (var i = 0; i < nodes.length; ++i) {
var node = nodes[i];
//dump("selectionnode["+i+"]: "+node+"\n");
// Disallow dragging the root node of a tree
var parent = this._getNodeParent(node);//node.parent;
//dump("parent: "+parent+"\n");
if (!parent)
throw Cr.NS_OK;
// If this node is part of a readonly container (e.g. a livemark) it
// cannot be moved, only copied, so we must change the action used
// by the drag session.
//if (PlacesUtils.nodeIsReadOnly(parent)) {
if (this.nodeIsReadOnly(parent)){
dragAction.action = Ci.nsIDragService.DRAGDROP_ACTION_COPY;
break;
}
}
if (event.ctrlKey)
dragAction.action = Ci.nsIDragService.DRAGDROP_ACTION_COPY;
// Stuff the encoded selection into the transferable data object
xferData.data = this.getTransferData(dragAction);
//dump("dragstartdone: "+xferData.data+"\n");
//xferData.data = this._controller.getTransferData(dragAction.action);
}catch(e){
//dump("error: "+e+"\nStack: "+e.stack+"\n");
Components.utils.reportError(e);
}
]]></body>
</method>
<!-- nsDragAndDrop -->
<method name="getSupportedFlavours">
<body><![CDATA[
//dump("getsupportedflavours\n");
var flavorSet = new FlavourSet();
for (var i = 0; i < this.peerDropTypes.length; ++i)
flavorSet.appendFlavour(this.peerDropTypes[i]);
return flavorSet;
]]></body>
</method>
<!-- drag & drop -->
<field name="DROP_BEFORE" readonly="true">-1</field>
<field name="DROP_ON" readonly="true">0</field>
<field name="DROP_AFTER" readonly="true">1</field>
<method name="_getOrientation">
<parameter name="event"/>
<parameter name="targetEle"/>
<parameter name="dragSession"/>
<body><![CDATA[
var orientation;
var source = this._getTargetElement(dragSession.sourceNode);
if (event.originalTarget.tagName == "row" && targetEle){
if (event.clientX<targetEle.boxObject.x){
orientation = this.DROP_BEFORE;
}
else if (event.clientX>=targetEle.boxObject.x+targetEle.boxObject.width){
orienation = this.DROP_AFTER;
}
this._lastDND = this.getElementNode(source);
}
else{
var node = targetEle?this.getElementNode(targetEle):null;
var isContainer = node && this.nodeIsContainer(node);
if (isContainer){
orientation = this.DROP_ON;
this._lastDND = this.getElementNode(targetEle);
} else{
if (targetEle && targetEle.nextSibling == source){
orientation = this.DROP_BEFORE;
}
else if (targetEle && targetEle.previousSibling == source){
orientation = this.DROP_AFTER;
}
else{
var mid = targetEle.boxObject.x+targetEle.boxObject.width/2;
if (event.clientX<mid)
orientation = this.DROP_BEFORE;
else
orientation = this.DROP_AFTER;
}
this._lastDND = this.getElementNode(source);
}
}
return orientation;
]]></body>
</method>
</implementation>
<handlers>
<handler event="dragover"><![CDATA[
nsDragAndDrop.dragOver(event, this);
]]></handler>
<handler event="dragdrop"><![CDATA[
nsDragAndDrop.drop(event, this);
]]></handler>
<handler event="keypress"><![CDATA[
this.handleKeypress(event);
]]></handler>
<handler event="mousedown"><![CDATA[
var target = this._getClickTarget(event);
if (!target) return;
if (event.button == 1){
/* middle click should open it in tabs */
this.performAction(event);
}
this.selectElement(target,event);
]]></handler>
<handler event="dblclick"><![CDATA[
this.performAction(event);
]]></handler>
</handlers>
</binding>
<binding id="thumbnailview-ff2" extends="chrome://bookmarkpreviews/content/thumbnailview.xml#thumbnailview">
<implementation>
<constructor><![CDATA[
// We implement nsIController
this.container.controllers.appendController(this.controller);
this.superConstructor();
]]></constructor>
<destructor><![CDATA[
//dump("destructor\n");
this.container.controllers.removeController(this.controller);
]]>
</destructor>
<property name="utils">
<getter>return BookmarksPreviewUtils;</getter>
</property>
<method name="nodeIsReadOnly">
<parameter name="aNode"/>
<body><![CDATA[
return false;
]]></body>
</method>
<method name="nodeIsContainer">
<parameter name="aNode"/>
<body><![CDATA[
return aNode && RDFCU.IsContainer(BMDS, aNode);
]]></body>
</method>
<method name="_getNodeParent">
<parameter name="aResource"/>
<body><![CDATA[
return BMDS.getParent(aResource);
]]></body>
</method>
<method name="getParentResource">
<parameter name="aResource"/>
<body><![CDATA[
return this._getNodeParent(aResource);
]]></body>
</method>
<property name="currentIndex">
<getter><![CDATA[
return this.getElementIndex(this.selectedItem);
]]></getter>
</property>
<property name="currentResource">
<getter><![CDATA[
return this.selectedNode;
]]></getter>
</property>
<property name="isSorted">
<getter><![CDATA[
return ThumbViewUtils.isSorted();
]]></getter>
</property>
<field name="_selection">null</field>
<field name="_target">null</field>
<method name="getViewSelection">
<body><![CDATA[
var resource = this.selectedNode;
if (!resource){
resource = this.utils.displayRoot;
}
var parent = BMDS.getParent(resource);
var selection = BookmarksUtils.getSelectionFromResource(resource, parent);
//dump("getviewselection: "+selection+"\n");
return selection;
]]></body>
</method>
<method name="getViewTarget">
<parameter name="aItem"/>
<parameter name="aParent"/>
<parameter name="aOrientation"/>
<body><![CDATA[
if (!aParent || aParent.Value == "NC:BookmarksTopRoot")
return BookmarksUtils.getTargetFromFolder(RDF.GetResource("NC:BookmarksRoot"))
if (aOrientation == BookmarksUtils.DROP_ON)
return BookmarksUtils.getTargetFromFolder(aItem);
RDFC.Init(BMDS, aParent);
var index = RDFC.IndexOf(aItem);
if (aOrientation == BookmarksUtils.DROP_AFTER)
++index;
return { parent: aParent, index: index };
]]></body>
</method>
<method name="onSelectionChanged">
<parameter name="aEvent"/>
<parameter name="aSelectedIndex"/>
<body><![CDATA[
//dump("fftthumbonselectionchanged\n");
this._selection = this.getViewSelection();
this._target = this.getViewTarget(this._selection.item[0], this._selection.parent[0], BookmarksUtils.DROP_BEFORE);
this.onCommandUpdate();
]]></body>
</method>
# This function saves the current selection state before the tree is rebuilt
# following a command execution. This allows us to remember which item(s)
# was/were selected so that the user does not need to constantly refocus the
# tree to perform a sequence of commands.
<field name="_savedSelection">null</field>
<method name="saveSelection">
<body><![CDATA[
this._savedSelection = this.selectedNode;
]]></body>
</method>
# This function restores the selection appropriately after a command executes.
# This is necessary because most commands trigger a rebuild of the tree which
# destroys the selection. The restoration of selection is handled in three
# different ways depending on the type of command that has been executed
<method name="restoreSelection">
<parameter name="aCommand"/>
<body><![CDATA[
this.selectNode(this._savedSelection);
this._savedSelection = null;
]]></body>
</method>
<method name="createViewContextMenu">
<parameter name="aEvent"/>
<body><![CDATA[
try{
var selection = this._selection;
var target = this._target;
//dump("createViewContextMenu: "+selection+"|"+target+"\n");
BookmarksCommand.createContextMenu(aEvent, selection);
this.onCommandUpdate();
}catch(e){Components.utils.reportError(e);}
]]></body>
</method>
<!-- Drag and drop -->
<method name="onDrop">
<parameter name="event"/>
<parameter name="dropData"/>
<parameter name="dragSession"/>
<body><![CDATA[
try{
//dump("onDrop\n");
var selection = BookmarksUtils.getSelectionFromXferData(dragSession);
var targetEle = this._lastDragTarget;
if (!targetEle) return;
var rItem = this.getElementNode(targetEle);
var rParent = BMDS.getParent(rItem);
var orientation = this._getOrientation(event,targetEle,dragSession);
//dump("orientation: "+orientation+"\n");
var target = this.getViewTarget(rItem, rParent, orientation);
ThumbViewUtils.updatedSelection = true;
var checkCopy = dragSession.isDataFlavorSupported("moz/rdfitem");
const kCopyAction = kDSIID.DRAGDROP_ACTION_COPY + kDSIID.DRAGDROP_ACTION_LINK;
// doCopy defaults to true; check if we should make it false.
// we make it false only if all the selection items have valid parent
// bookmark DS containers (i.e. aren't generated via aggregation)
var doCopy = true;
if (checkCopy && !(dragSession.dragAction & kCopyAction))
doCopy = BookmarksUtils.shouldCopySelection("drag", selection);
try{
if (doCopy)
BookmarksUtils.insertAndCheckSelection("drag", selection, target);
else
BookmarksUtils.moveAndCheckSelection ("drag", selection, target);
}catch(e){
Components.utils.reportError("ThumbnailError: "+e);
}
ThumbViewUtils.updatedSelection = false;
ThumbViewUtils.refreshDisplay();
this.selectNode(BookmarksPreviewUtils._lastTransactionItem);
//setTimeout( function (){ThumbViewUtils.updatedSelection = false},0);
//dump("ondrop complete\n");
return;
}catch(e){Components.utils.reportError(e);}
]]></body>
</method>
<field name="_lastDragTarget">null</field>
<!-- nsDragAndDrop -->
<method name="onDragOver">
<parameter name="event"/>
<parameter name="flavor"/>
<parameter name="session"/>
<body><![CDATA[
session.canDrop = true;
]]></body>
</method>
<method name="canDrop">
<parameter name="event"/>
<parameter name="dragSession"/>
<body><![CDATA[
//dump("candrop\n");
var selection = BookmarksUtils.getSelectionFromXferData(dragSession);
var isBookmark = dragSession.isDataFlavorSupported("moz/rdfitem");
if (isBookmark && selection.containsImmutable)
return false;
//TODO actually find the orientation
var orientation = BookmarksUtils.DROP_ON;
var targetEle = this._getTargetElement(event.originalTarget);
//dump("candrop: "+event.target.tagName+"|"+event.originalTarget.tagName+"\n");
//dump("x: "+event.clientX+"\n");
if (!targetEle && event.originalTarget.tagName!="row")
return false;
if (targetEle)
this._lastDragTarget = targetEle;
if (orientation == BookmarksUtils.DROP_ON)
return true;
var rsrc = this.mOuter.getRowResource(index);
var rsrcParent = this.mOuter.getParentResource(index);
var rtype = BookmarksUtils.resolveType(rsrc);
var rptype = BookmarksUtils.resolveType(rsrcParent);
if (!BookmarksUtils.isValidTargetContainer (rsrcParent, selection))
return false;
if (index != 0)
return true;
if (rsrc.Value != "NC:BookmarksRoot")
return true;
return orientation == BookmarksUtils.DROP_BEFORE ? false : this.mOuter.treeBoxObject.view.isContainerOpen(0)
return true;
]]></body>
</method>
<method name="getTransferData">
<parameter name="dragAction"/>
<body><![CDATA[
try{//var selection = this._selection;
var resource = this.selectedNode;
var parent = BMDS.getParent(resource);
var selection = BookmarksUtils.getSelectionFromResource(resource, parent);
//dump("getTransferData: "+selection+"\n");
return BookmarksUtils.getXferDataFromSelection(selection);
}catch(e){Components.utils.reportError(e);return null;}
]]></body>
</method>
<field name="peerDropTypes"><![CDATA[
["moz/rdfitem",
"application/x-moz-file",
"text/x-moz-url",
"text/unicode"
]
]]></field>
<field name="childDropTypes">this.peerDropTypes</field>
<!-- nsIController -->
<field name="controller" readonly="true"><![CDATA[
({
mOuter: this,
supportsCommand: BookmarksController.supportsCommand,
isCommandEnabled: function (aCommand)
{
//dump("ice: "+aCommand+"\n"); return;
// warning: this is not the called function in BookmarksController.onCommandUpdate
var selection = this.mOuter._selection;
var target = this.mOuter._target;
return BookmarksController.isCommandEnabled(aCommand, selection, target)
},
doCommand: function (aCommand)
{
//dump("doCOmmand: "+aCommand+"\n");
var selection = this.mOuter._selection;
var target = this.mOuter._target;
//var selection = ThumbViewUtils._selection;
//var target = ThumbViewUtils._target;
//this.mOuter.treeBoxObject.view.selection.selectEventsSuppressed = true;
//this.mOuter._itemToBeToggled = [];
switch (aCommand) {
case "cmd_selectAll":
//this.mOuter.treeBoxObject.view.selection.selectAll();
break;
default:
//this.mOuter.saveSelection();
BookmarksController.doCommand(aCommand, selection, target);
//this.mOuter.restoreSelection(aCommand);
}
//this.mOuter.treeBoxObject.view.selection.selectEventsSuppressed = false;
}
})
]]></field>
<method name="onCommandUpdate">
<body><![CDATA[
var selection = this._selection;
var target = this._target;
//dump("oncommandupdate: "+selection+"|"+target+"\n");
BookmarksController.onCommandUpdate(selection, target);
]]></body>
</method>
</implementation>
</binding>
<binding id="thumbnailview-ff3" extends="chrome://bookmarkpreviews/content/thumbnailview.xml#thumbnailview">
<implementation>
<constructor><![CDATA[
this.superConstructor();
this.container.setAttribute("context","placesContext");
]]></constructor>
<destructor><![CDATA[
//dump("destructor\n");
]]>
</destructor>
<property name="utils">
<getter>return PlacesPreviewUtils;</getter>
</property>
<property name="controller"
readonly="true"
onget="return this._controller;"/>
<property name="isSorted">
<getter><![CDATA[
return this.getResult().sortingMode != Ci.nsINavHistoryQueryOptions.SORT_BY_NONE
]]></getter>
</property>
<method name="getBestOptions">
<body><![CDATA[
// Get the best set of grouping options to use, either reuse the
// existing ones or create new ones.
var options = this.getResult().queryOptions;
if (!options)
options = PlacesUtils.history.getNewQueryOptions();
return options;
]]></body>
</method>
<method name="nodeIsReadOnly">
<parameter name="aNode"/>
<body><![CDATA[
return PlacesUtils.nodeIsReadOnly(aNode);
]]></body>
</method>
<method name="nodeIsContainer">
<parameter name="aNode"/>
<body><![CDATA[
return aNode && PlacesUtils.nodeIsContainer(aNode);
]]></body>
</method>
<method name="createViewContextMenu">
<parameter name="aEvent"/>
<body><![CDATA[
try{
}catch(e){Components.utils.reportError(e);}
]]></body>
</method>
<field name="selType">"single"</field>
<method name="onCommandUpdate">
<body><![CDATA[
//dump("oncommandupdate\n");
goUpdatePlacesCommands();
goUpdateGlobalEditMenuItems();
goUpdateUndoEditMenuItems();
goUpdatePasteMenuItems();
]]></body>
</method>
<method name="buildContextMenu">
<parameter name="aPopup"/>
<body><![CDATA[
//dump("build context menu - thumbnailview: "+aPopup+"\n");
this.onCommandUpdate();
ThumbViewUtils.updatedSelection = true;
var hasChildren = this.controller.buildContextMenu(aPopup);
ThumbViewUtils.updatedSelection = false;
return hasChildren;
]]></body>
</method>
<method name="destroyContextMenu">
<parameter name="aPopup"/>
<body/>
</method>
<method name="onSelectionChanged">
<parameter name="aEvent"/>
<parameter name="aSelectedIndex"/>
<body><![CDATA[
//dump("Selection changed\n");
]]></body>
</method>
<property name="showRoot">
<getter><![CDATA[
return false;
]]></getter>
</property>
<!-- not really implemented -->
<property name="flatList">
<getter><![CDATA[
return this.getAttribute("flatList") == "true";
]]></getter>
<setter><![CDATA[
if (this.flatList != val) {
this.setAttribute("flatList", val);
// reload with the last place set
if (this.place)
this.place = this.place;
}
return val;
]]></setter>
</property>
<field name="_result">null</field>
<!-- nsIPlacesView -->
<method name="getResult">
<body><![CDATA[
try {
return this._result;
}
catch (e) {
return null;
}
]]></body>
</method>
<!-- nsIPlacesView -->
<method name="getResultNode">
<body><![CDATA[
return this.getResult().root;
]]></body>
</method>
<field name="view">null</field>
<method name="getResultView">
<body><![CDATA[
try {
return this.getResult().viewer;
}
catch (e) {
}
return null;
]]></body>
</method>
<!-- nsIPlacesView -->
<property name="place">
<getter><![CDATA[
return this.getAttribute("place");
]]></getter>
<setter><![CDATA[
this.setAttribute("place", val);
var queriesRef = { };
var queryCountRef = { };
var optionsRef = { };
PlacesUtils.history.queryStringToQueries(val, queriesRef, queryCountRef, optionsRef);
if (queryCountRef.value == 0)
queriesRef.value = [PlacesUtils.history.getNewQuery()];
if (!optionsRef.value)
optionsRef.value = PlacesUtils.history.getNewQueryOptions();
this.loadQuery(queriesRef.value, optionsRef.value);
return val;
]]></setter>
</property>
<method name="loadQuery">
<parameter name="queries"/>
<parameter name="options"/>
<body><![CDATA[
this._result = PlacesUtils.history.executeQueries(queries, queries.length,
options);
var thumbView = new PlacesThumbView(this.showRoot, this.flatList);
//thumbView = new PlacesPreviewTreeView(thumbView, "thumbnail");
extendPreviewView(thumbView,"thumbnail");
this._result.viewer = thumbView;
var bkmks = [];
this.utils.getBookmarkImages(bkmks,this.getResultNode());
this.load(bkmks);
if (!this._controller) {
this._controller = new PlacesController(this);
this.container.controllers.appendController(this._controller);
}
this._cachedInsertionPoint = undefined;
]]></body>
</method>
<!-- nsIPlacesView -->
<property name="hasSelection">
<getter><![CDATA[
return this.selectedItem !=null;
]]></getter>
</property>
<!-- nsIPlacesView -->
<property name="hasSingleSelection">
<getter><![CDATA[
/* currently only supports single selection */
return this.hasSelection;
]]></getter>
</property>
<!-- nsIPlacesView -->
<!-- implemented in the extended thumbnail binding
<method name="getSelectionNodes">
-->
<!-- nsIPlacesView -->
<method name="getRemovableSelectionRanges">
<body><![CDATA[
var node = this.selectedNode;
if (node)
return [[node]];
return [];
]]></body>
</method>
<!-- nsIPlacesView -->
<method name="getCopyableSelection">
<body><![CDATA[
return this.getSelectionNodes();
]]></body>
</method>
<!-- nsIPlacesView -->
<method name="getDragableSelection">
<body><![CDATA[
var nodes = this.getSelectionNodes();
for (var i = nodes.length - 1; i >= 0; i--) {
if (PlacesUtils.nodeIsReadOnly(this._getNodeParent(nodes[i])))
nodes.splice(i, 1);
}
return nodes;
]]></body>
</method>
<!-- nsIPlacesView -->
<!-- implemented in the extended thumbnail component
<property name="selectedNode">
-->
<!-- nsIPlacesView -->
<property name="selectedURINode">
<getter><![CDATA[
var node = this.selectedNode;
if (PlacesUtils.nodeIsURI(node))
return node;
return null;
]]></getter>
</property>
<!-- nsIPlacesView -->
<property name="insertionPoint">
<getter><![CDATA[
// invalidated on selection and focus changes
if (this._cachedInsertionPoint !== undefined)
return this._cachedInsertionPoint;
// there is no insertion point for history queries
// so bail out now and save a lot of work when updating commands
var resultNode = this.getResultNode();
if (PlacesUtils.nodeIsQuery(resultNode)) {
var options = asQuery(resultNode).queryOptions;
if (options.queryType == options.QUERY_TYPE_HISTORY)
return this._cachedInsertionPoint = null;
}
var orientation = Ci.nsITreeView.DROP_AFTER;
// This is a two-part process. The first part is determining the drop
// orientation.
// * The default orientation is to drop _after_ the selected item.
// * If the selected item is an open container, the default
// orientation is to drop _into_ that container.
//
// Warning: It may be tempting to use tree indexes in this code, but
// you must not, since the tree is nested and as your tree
// index may change when folders before you are opened and
// closed. You must convert your tree index to a node, and
// then use getIndexOfNode to find your absolute index in
// the parent container instead.
//
// If the sole selection is an open container, insert into it rather
// than adjacent to it. Note that this only applies to _single_
// selections - if the last element within a multi-selection is an
// open folder, insert _adajacent_ to the selection.
//
// If the sole selection is the bookmarks toolbar folder, we insert
// into it even if it is not opened
if (this.hasSingleSelection &&
this.nodeIsContainer(this.selectedNode))
orientation = Ci.nsITreeView.DROP_ON;
this._cachedInsertionPoint =
this._getInsertionPoint(this.getElementIndex(this.selectedItem)
, orientation);
return this._cachedInsertionPoint;
]]></getter>
</property>
<method name="_disallowInsertion">
<parameter name="aContainer"/>
<body><![CDATA[
// Disallow insertion of items under readonly folders
// Disallow insertion of items under the places root
return (!PlacesUtils.nodeIsFolder(aContainer) ||
PlacesUtils.nodeIsReadOnly(aContainer) ||
aContainer.itemId == PlacesUtils.placesRootId);
]]></body>
</method>
<method name="_getInsertionPoint">
<parameter name="index"/>
<parameter name="orientation"/>
<body><![CDATA[
//return null; //TODO fix
var result = this.getResult();
var container = result.root;
NS_ASSERT(container, "null container");
// When there's no selection, assume the container is the container
// the view is populated from (i.e. the result's itemId).
if (index != -1) {
var lastSelected = this.nodeForIndex(index);
if (this.isContainer(index) && orientation == Ci.nsITreeView.DROP_ON) {
// If the last selected item is an open container, append _into_
// it, rather than insert adjacent to it.
container = lastSelected;
index = -1;
}
/* This doesn't apply in the thumbnail view
else if (!this._disallowInsertion(lastSelected) &&
lastSelected.containerOpen &&
orientation == Ci.nsITreeView.DROP_AFTER) {
// If the last selected item is an open container and the user is
// trying to drag into it as a first item, really insert into it.
container = lastSelected;
orientation = Ci.nsITreeView.DROP_BEFORE;
index = 0;
}
*/
else {
// Use the last-selected node's container unless the root node
// is selected, in which case we use the root node itself as the
// insertion point.
container = this._getNodeParent(lastSelected) || container;
// avoid the potentially expensive call to getIndexOfNode()
// if we know this container doesn't allow insertion
if (this._disallowInsertion(container))
return null;
var lsi = PlacesUtils.getIndexOfNode(lastSelected);
index = (orientation == Ci.nsITreeView.DROP_BEFORE) ? lsi : lsi + 1;
}
}
if (this._disallowInsertion(container))
return null;
return new InsertionPoint(container.itemId, index, orientation);
]]></body>
</method>
<!-- nsIPlacesView -->
<field name="peerDropTypes">PlacesUIUtils.GENERIC_VIEW_DROP_TYPES</field>
<!-- nsIPlacesView -->
<field name="childDropTypes">PlacesUIUtils.GENERIC_VIEW_DROP_TYPES</field>
<!-- nsIPlacesView -->
<!-- currently only single selection support -->
<method name="selectAll">
<body><![CDATA[
//this.view.selection.selectAll();
]]></body>
</method>
<method name="_getNodeParent">
<parameter name="aNode"/>
<body><![CDATA[
return aNode.parent;
]]></body>
</method>
<!-- drag and drop -->
<method name="getTransferData">
<parameter name="dragAction"/>
<body><![CDATA[
return this._controller.getTransferData(dragAction.action);
]]></body>
</method>
<!-- Drag and drop -->
<method name="_getSourceView">
<parameter name="dragSession"/>
<body><![CDATA[
var sourceNode = dragSession.sourceNode;
/* sourceView doesn't really seem to be used so there
is no real point in implementing this. onDrop in the drag
helper takes a sourceView as its first argument though.*/
return this;
]]></body>
</method>
<field name="_lastDND">null</field>
<!-- Drag and drop -->
<method name="onDrop">
<parameter name="event"/>
<parameter name="dropData"/>
<parameter name="dragSession"/>
<body><![CDATA[
try{
var targetEle = this._lastDragTarget;
var orientation = this._getOrientation(event,targetEle,dragSession);
ThumbViewUtils.updatedSelection = true;
var index = this.getElementIndex(this._lastDragTarget);// + orientation;
LOG("VOThumb: onDrop: " + index + ", orientation: " + orientation);
if (!this.canDrop(event,dragSession))
return;
// We are responsible for translating the |index| and |orientation|
// parameters into a container id and index within the container,
// since this information is specific to the view.
var ip = this._getInsertionPoint(index, orientation);
//dump("ip: "+index+"|"+ip.index+" orient: "+orientation+"\n");
if (!ip)
throw Cr.NS_ERROR_NOT_AVAILABLE;
//var sourceView = this._getSourceView(dragSession);
PlacesControllerDragHelper.onDrop(ip);
ThumbViewUtils.updatedSelection = false;
this.selectNode(this._lastDND);
return;
}catch(e){Components.utils.reportError(e);}
]]></body>
</method>
<field name="_lastDragTarget">null</field>
<!-- nsDragAndDrop -->
<method name="onDragOver">
<parameter name="event"/>
<parameter name="flavor"/>
<parameter name="session"/>
<body><![CDATA[
session.canDrop = true;
]]></body>
</method>
<method name="canDrop">
<parameter name="event"/>
<parameter name="dragSession"/>
<body><![CDATA[
var result = this.getResult(), node = null;
var targetEle = this._getTargetElement(event.originalTarget);
if (!targetEle && event.originalTarget.tagName!="row")
return false;
if (targetEle){
this._lastDragTarget = targetEle;
node = this.getElementNode(targetEle);
}
var orientation = this._getOrientation(event,this._lastDragTarget,dragSession);
//dump("candrop orientation: "+orientation+"\n");
if (orientation == this.DROP_ON) {
// The user cannot drop an item into itself or a read-only container
var sourceEle = this._getTargetElement(dragSession.sourceNode);
if (sourceEle == targetEle || PlacesUtils.nodeIsReadOnly(node))
return false;
}
else if (node && node.parent && PlacesUtils.nodeIsReadOnly(node.parent))
return false;
return PlacesControllerDragHelper.canDrop(this, orientation);
]]></body>
</method>
</implementation>
</binding>
</bindings>